<?php
   	include ('../inc/config.php');

    $q = trim($_GET['term']);

    $sql = "select titulo, id from productos where (titulo like '%$q%') and activo=1 order by titulo ASC";
    $rs = $db->SelectLimit($sql,20);
    $Busquedas = $rs->GetRows();
	//pr($Busquedas);
	if ($Busquedas){
		$items=array();
		foreach($Busquedas as $r){
			$items[$r['titulo']] = $r['id'];
		}
	}
	
	
if (!$q) return;

//pr($items);
$result = array();
foreach ($items as $key=>$value) {
	if (strpos(strtolower($key), $q) !== false) {
		array_push($result, array("id"=>$value, "label"=>$key, "value" => strip_tags($key)));
	}
	if (count($result) > 11)
		break;
}

echo array_to_json($result);

?>